package com.cuitrip.business.home.travel.ui;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.cuitrip.business.home.travel.model.FilterInfo;
import com.cuitrip.util.adapter.CTRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ak
 */
public class FilterAdapter extends CTRecyclerAdapter<FilterInfoViewHolder> {
    public static final String TAG = "FilterAdapter";
    private List<FilterInfo> mModeList = new ArrayList<>();

    public FilterAdapter(List<FilterInfo> filterInfoList) {
        this.mModeList = filterInfoList;
    }

    public int getListSize(List list) {
        return list == null ? 0 : list.size();
    }

    public void setModeList(List<FilterInfo> modeList) {
        mModeList.clear();
        mModeList.addAll(modeList);
        notifyItemRangeChanged(0, modeList.size());
    }

    public FilterInfo getItem(int position) {
        if (position >= 0 && position < mModeList.size()) {
            return mModeList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public FilterInfoViewHolder newViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(FilterInfoViewHolder.RES, parent, false);
        FilterInfoViewHolder viewHolder = new FilterInfoViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(FilterInfoViewHolder holder, int position) {
        holder.render(mModeList.get(position));
    }

    @Override
    public int getItemCount() {
        return mModeList == null ? 0 : mModeList.size();
    }
}
